<?php
namespace ulue\ext\zui;

use ulue\libs\front\Html;
use ulue\libs\front\Paging;

class ZuiPaging extends Paging
{
    public $elements = [
          'box'               => [
                'tag'             => 'ul', //'div>ul',
                'class'           => 'pager',
          ],
          'list'              => [
                'tag'             => 'li',
                'currentClass'    => 'active',
          ],
          'link'              => [
                'tag'             => 'a',
                // 'currentClass'    => 'active',
          ],
      ];

    //得到回到第一页字符串
    public function getFirstPage()
    {
        $first = Html::startTag('li');
        $first .= Html::a($this->textSet['first'],$this->getUrl(1),['title'=>$this->textSet['first']]);
        $first .= Html::endTag('li');

        return $first;
    }

    //得到上一页,当前页数大于1时，出现 ‘上一页’ 按钮
    public function getPrevPage()
    {
        $prev = '';

        if ($this->currentPage > 1)
        {
            $prev = Html::startTag('li');
            $prev .= Html::a($this->textSet['prev'],$this->getUrl($this->prevPage),['title'=>$this->textSet['prev']]);
            $prev .= Html::endTag('li');
        }

        return $prev;
    }

    //向上跳转 $this->displayBtnNum 的页数
    public function getPrevAcrossPages()
    {
        $prevAcrossPages = $this->currentPage - $this->displayBtnNum;
        $prevs = '';

        if ($prevAcrossPages > 0)
        {
            $text  = sprintf($this->textSet['prevs'],$this->displayBtnNum);
            $prevs = Html::startTag('li');
            $prevs .= Html::a($text,$this->getUrl($prevAcrossPages),['title'=>$text]);
            $prevs .= Html::endTag('li');
        }

        return $prevs;
    }

    //得到数字按钮分页字符串
    public function getNumBtnPage($numBtnPage='')
    {
        for($i=$this->firstNumBtn;$i<=$this->lastNumBtn;$i++)
        {
            if ($i==$this->currentPage)
            {
               //给当前页按钮设置额外样式
               $numBtnPage .= Html::startTag('li',['class'=>$this->elements['list']['currentClass']]);
               $numBtnPage .= Html::a($i,'javascript:;');
               $numBtnPage .= Html::endTag('li');
            } else {
               $numBtnPage .= Html::startTag('li');
               $numBtnPage .= Html::a($i,$this->getUrl($i));
               $numBtnPage .= Html::endTag('li');
            }

        }

        return $numBtnPage;
    }

    //向下跳转 $this->displayBtnNum 的页数
    public function getNextAcrossPages()
    {
        $nextAcrossPages = $this->currentPage + $this->displayBtnNum;
        $nexts = '';

        if ($nextAcrossPages < $this->allPage)
        {
            $text  = sprintf($this->textSet['nexts'],$this->displayBtnNum);
            $nexts = Html::startTag('li');
            $nexts .= Html::a($text,$this->getUrl($nextAcrossPages),['title'=>$text]);
            $nexts .= Html::endTag('li');
        }

        return $nexts;
    }

    //得到下一页,当前页数小于总页数时，出现 ‘下一页’ 按钮
    public function getNextPage()
    {
        $next = '';

        if ($this->currentPage < $this->allPage)
        {
           $next = Html::startTag('li');
           $next .= Html::a($this->textSet['next'],$this->getUrl($this->nextPage),['title'=>$this->textSet['next']]);
           $next .= Html::endTag('li');
        }

       return $next;
    }

}